package com.distribute.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.web.http.DefaultCookieSerializer;

import com.distribute.common.Constant;


@Configuration
public class SpringSessionConfig {
	
	@Value(value="${spring.session.timeout}")
	private String sessionTimeOut;
	
	private Logger log = LoggerFactory.getLogger(SpringSessionConfig.class);
	
	@Bean
	public DefaultCookieSerializer defaultCookieSerializer() {
		log.info("自定义cookie序列化加载成功");
		DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();
		defaultCookieSerializer.setCookieMaxAge(Integer.parseInt(sessionTimeOut));
		defaultCookieSerializer.setCookieName(Constant.COOKIE_NAME);
		defaultCookieSerializer.setUseBase64Encoding(true);
		defaultCookieSerializer.setCookiePath("/");
		//defaultCookieSerializer.setDomainName("happylaishop.top");
		defaultCookieSerializer.setUseHttpOnlyCookie(true);
		return defaultCookieSerializer;
	}
	
}
